package org.ucas.kgraph.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.ucas.kgraph.entity.Term;

import java.util.List;

@Repository
public interface TermDao extends JpaRepository<Term,Long>{

  @Query("FROM Term t WHERE t.definition = ?1 AND t.rootId = ?2")
  public Term findByDefinition(String definition, Long rootId);
  
  @Query("FROM Term t WHERE t.tags like %?1%")
  public List<Term> searchByTag(String tag);
  
  @Query("FROM Term t WHERE t.definition = ?1")
  public List<Term> searchCurrByDefinition(String definition);
  
  @Query("FROM Term t WHERE t.tags = ?1")
  public List<Term> searchCurrByTag(String tags);
  
  @Query("FROM Term t WHERE t.definition like %?1%")
  public List<Term> searchByDefinition(String definition);

  @Query("FROM Term t WHERE t.id in :ids")
  public List<Term> loadBatch(@Param("ids") List<Long> ids);

  @Query("FROM Term t WHERE t.rootId = ?1 AND t.file_id=?2")
  public List<Term> listUnderRoot(Long rootId,Long file_id);
  
  @Query("FROM Term t WHERE t.definition like %?1% AND t.file_id=?2 AND t.rootId = ?3")
  public List<Term> searchRootByDefinition(String definition, Long fileId, Long rootId);
 


}
